package com.hktf.uilib.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.hktf.corelib.utils.LogMds;

public class DiaSystemDBHelper extends SQLiteOpenHelper {

	private static final String TB_NAME_DIASYSTEM_INFO_TB="diasystem_info_tb";//最近诊断系统表名
	private static final String DIASYSTEM_TYPE="diasystem_type";//1诊断 2ureapump  3Nitrogen_oxygen_sensor 4sensor_test 5egr_test 6injector_test
	// 7metering_valve_test 8other_valve_test 9motor_test 10temperature_sensor_test
	// 11liquidlevel_sensor_test 12pressure_sensor_test 13sensor_signal_test

	// 数据库版本号
	private static final int CURR_VERSION = 5;
	// 数据库名称
	private static final String DB_NAME = "DiaSystem_db";
	private static final String CREATE_DIASYSTEM_TB = "CREATE TABLE if not exists " + TB_NAME_DIASYSTEM_INFO_TB
			+ "(_id integer primary key autoincrement,"
			+ "name varchar,"
			+ "path varchar,"
			+ "pathID varchar,"
			+ "time varchar,"
			+ "isdemo integer,"
			+ "captionpath varchar,"
			+ DIASYSTEM_TYPE + " integer default (1))";


	public DiaSystemDBHelper(Context context) {
		super(context, DB_NAME, null, CURR_VERSION);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL(CREATE_DIASYSTEM_TB);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		LogMds.i("cdz","DiaSystemDB onUpgrade");
		if(oldVersion<4){
			db.execSQL("drop table if exists diasystem_info_tb");
			db.execSQL("CREATE TABLE if not exists " + TB_NAME_DIASYSTEM_INFO_TB
					+ "(_id integer primary key autoincrement,"
					+ "name varchar,"
					+ "path varchar,"
					+ "pathID varchar,"
					+ "time varchar,"
					+ "isdemo integer,"
					+ "captionpath varchar,"
					+ DIASYSTEM_TYPE + " integer default (1))");
		}else if(oldVersion<5){
			db.execSQL("ALTER TABLE " + TB_NAME_DIASYSTEM_INFO_TB + " ADD COLUMN "
					+ DIASYSTEM_TYPE + " integer default (1);");

		}

	}

}
